public class MyQueue {
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode first;
    public ListNode last;
    int size;
    //入队列
    public void offer(int s){
        ListNode newnode = new ListNode(s);
        if(first == null){
            first = last = newnode;
        }else {
            last.next = newnode;
            newnode.prev = last;
        }
        last = newnode;
        size++;
    }
    //出队列
    public int poll(){
        int val = first.val;
        //判断队列为空
        if(first == null){
            return -1;
        }else if(first == last){//队列只有一个元素
            last = first = null;
        }else {//队列有多个元素
            first = first.next;
            first.prev = null;
        }
        return val;

    }
    //获取队头元素
    public int peek(){
        if(first == null){
            return -1;
        }
        return first.val;
    }
    public int size(){
       ListNode cur = first;
       int count = 0;
       while (cur != null){
           cur = cur.next;
           count++;
       }
       return count;
    }
    public boolean isEmpty(){
        return first == null;
    }


}
